/*
 * @Author: 刘鑫
 * @Date: 2020-11-10 15:08:05
 * @LastEditors: 刘鑫
 * @LastEditTime: 2020-11-11 20:12:20
 * @Description:
 */
import {
  getHomeList,
  getBannerList,
  getList,
  getRankList,
  getRecommendList,
  getLiveList,
  getVideoList,
  getCodeList,
  getAthleticsList,
  getBusinessList,
  getCarList,
  getElseList
} from "@/api/home";

const state = {
  rankCategoryList: [],
  bannerList: [],
  list: [],
  cityList: [],
  recommedList: [], //推荐严选数据
  liveList: [], //生活严选数据
  videoList: [], //影音严选数据
  codeList: [], //数码严选数据
  athleticsList: [], //竞技严选数据
  businessList: [], //商业严选数据
  carList: [], //汽车严选数据
  elseList: [] //其他严选数据
};

const mutations = {
  updateCategoryList(state, payload) {
    state.rankCategoryList = payload;
  },
  updateBannerList(state, payload) {
    state.bannerList = payload;
  },
  updateList(state, payload) {
    state.list = payload;
  },
  updateCityList(state, payload) {
    state.cityList = payload;
  },
  //推荐严选数据
  getRecommendList(state, val) {
    state.recommedList = val;
  },
  //生活严选数据
  getLiveList(state, val) {
    state.liveList = val;
  },
  //影音严选数据
  getVideoList(state, val) {
    state.videoList = val;
  },
  //数码严选数据
  getCodeList(state, val) {
    state.codeList = val;
  },
  //竞技严选数据
  getAthleticsList(state, val) {
    state.athleticsList = val;
  },
  //商业严选数据
  getBusinessList(state, val) {
    state.businessList = val;
  },
  //汽车严选数据
  getCarList(state, val) {
    state.carList = val;
  },
  //其他严选数据
  getElseList(state, val) {
    state.elseList = val;
  }
};

const actions = {
  //Home
  async getHomeList({ commit }, payload) {
    let result = await getHomeList(payload);
    commit("updateCategoryList", result.rankCategoryList);
  },
  //banner
  async getBannerList({ commit }, payload) {
    let result = await getBannerList(payload);
    commit("updateBannerList", result.carouselList[0]);
  },
  //rankCategoryList
  async getList({ commit }, payload) {
    let result = await getList(payload);
    commit("updateList", result.dataList);
  },
  //rankPage
  async getCityList({ commit }, payload) {
    let result = await getRankList(payload);
    commit("updateCityList", result.dataList);
  },
  //首页推荐严选数据
  async getRecommendList({ commit }, val) {
    let result = await getRecommendList(val);
    console.log(result.dataList, "推荐");
    commit("getRecommendList", result.dataList);
  },
  //生活严选数据
  async getLiveList({ commit }, val) {
    let result = await getLiveList(val);
    commit("getLiveList", result.dataList);
  },
  //影音严选数据
  async getVideoList({ commit }, val) {
    let result = await getVideoList(val);
    commit("getVideoList", result.dataList);
  },
  //数码严选数据
  async getCodeList({ commit }, val) {
    let result = await getCodeList(val);
    commit("getCodeList", result.dataList);
  },
  //竞技严选数据
  async getAthleticsList({ commit }, val) {
    let result = await getAthleticsList(val);
    commit("getAthleticsList", result.dataList);
  },
  //商业严选数据
  async getBusinessList({ commit }, val) {
    let result = await getBusinessList(val);
    commit("getBusinessList", result.dataList);
  },
  //汽车严选数据
  async getCarList({ commit }, val) {
    let result = await getCarList(val);
    commit("getCarList", result.dataList);
  },
  //其他严选数据
  async getElseList({ commit }, val) {
    let result = await getElseList(val);
    commit("getElseList", result.dataList);
  }
};
const modules = {};
export default {
  namespaced: true,
  state,
  mutations,
  actions,
  modules
};
